package cn.itcast.service.impl;

import cn.itcast.dao.RouteDao;
import cn.itcast.dao.impl.RouteDaoImpl;
import cn.itcast.daomain.PageBean;
import cn.itcast.daomain.classification;
import cn.itcast.daomain.commodity;
import cn.itcast.service.RouteService;

import java.util.List;

public class RouteServiceImpl implements RouteService {
    private RouteDao routeDao=new RouteDaoImpl();
    @Override
    public PageBean<commodity> pageQuery(int cid,int currentPage, int pageSize) {
        PageBean<commodity> pd=new PageBean<commodity>();

        //设置当前页码
        pd.setCurrentPage(currentPage);
        //设置每页显示条数
        pd.setPageSize(pageSize);

        //设置总数量
        int totalCount= routeDao.findTotalCount(cid);
        pd.setTotalCount(totalCount);

        //设置当前页的数据集合
        int start=(currentPage-1)*pageSize; //开始的记录数
        List<commodity> list=routeDao.findByPage(cid,start,pageSize);
        pd.setList(list);

        //设置总页数 = 总数量/每页记录数
        int totalPage= totalCount % pageSize == 0 ? totalCount / pageSize : (totalCount / pageSize) +1;
        pd.setTotalPage(totalPage);

        return pd;
    }

    @Override
    public List<classification> classifications() {
        return routeDao.classifications();
    }
}
